home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWThread / FWThrdUt.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  1.2 KB  |  43 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWThrdUt.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11. #include "FWThrdUt.h"
  12.  
  13. //-----------------------------------------------------------------------------
  14. // FW_CThreadCriticalState
  15. // Enters a critical state and makes sure we exit it if an exception is thrown.
  16. //-----------------------------------------------------------------------------
  17.  
  18. FW_DEFINE_AUTO (FW_CPrivThreadCriticalState)
  19.  
  20. FW_CPrivThreadCriticalState::FW_CPrivThreadCriticalState ()
  21. {
  22.     OSErr result = ::ThreadBeginCritical();
  23.     FW_FailOnError (result);
  24.     fIsCritical = true;
  25. }
  26.  
  27. FW_CPrivThreadCriticalState::~FW_CPrivThreadCriticalState ()
  28. {
  29.     if (fIsCritical) {
  30.         OSErr result = ::ThreadEndCritical();
  31.         FW_FailOnError (result);
  32.     }
  33. }
  34.  
  35. void 
  36. FW_CPrivThreadCriticalState::SetThreadStateEndCritical (ThreadID theThread, ThreadState newState, ThreadID suggestedThread)
  37. {
  38.     OSErr result = ::SetThreadStateEndCritical (theThread, newState, suggestedThread);
  39.     FW_FailOnError (result);
  40.     fIsCritical = false;
  41. }
  42.  
  43.